package storage

import (
	"context"

	"mall/service/wpgql/api/internal/graph/model"
)

func (m *MemoryStorage) PutCategory(ctx context.Context, category *model.Category) error {
	m.categories[category.ID] = category

	return nil
}

func (m *MemoryStorage) GetCategories(ctx context.Context, ids []string) ([]*model.Category, error) {
	output := make([]*model.Category, 0, len(ids))
	for _, id := range ids {
		if category, ok := m.categories[id]; ok {
			output = append(output, category)
		}
	}

	return output, nil
}

func (m *MemoryStorage) GetAllCategories(ctx context.Context) ([]*model.Category, error) {
	output := make([]*model.Category, 0, len(m.categories))
	for _, category := range m.categories {
		output = append(output, category)
	}

	return output, nil
}
